{include file="public/header" /}
<title>{:lang('我的团队')}</title>
<header id="header" class="mui-bar mui-bar-nav">
    <div class="mui-pull-left PopupNavigation">
        <img src="/static/home/bl_1.png" alt="">
    </div>
    <h1 class="mui-title">{:lang('我的团队')}</h1>
    <div class="mui-pull-right" style="display: none;">
        <div class="mui-switch mui-active" >
            <div class="mui-switch-handle"></div>
        </div>
    </div>
</header>    
{include file="public/menu" /}
<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
    <div class="mui-scroll" style="transform: translate3d(0px, 0px, 0px) translateZ(0px); transition-duration: 0ms;">
        <div class="myTeamBox" id="teamInfo">
            <div class="iwanvesttl">
                <span class="span_1">{:lang('我的当前代理等级')}</span>
                <span class="span_2">{:lang($user['level'])}</span>
            </div>
            <div class="myTeamCont df">
                <div class="fx1">
                    <div class="span_1">{:lang('直推人数')}</div>
                    <div class="span_2"><span id="tjr_num">0</span></div>
                </div>
                <div class="fx1">
                    <div class="span_1">{:lang('团队人数')}</div>
                    <div class="span_2"><span id="team_num">0</span></div>
                </div>
                <div class="fx1">
                    <div class="span_1">{:lang('团队投资金额')}</div>
                    <div class="span_2">$<span id="team_invest_total">0</span></div>
                </div>
            </div>
        </div>
        <div class="returnpushBox" style="display:none;" id="close_btn">
            <button class="returnpushan click_close">{:lang('关闭')}</button>
        </div>
        <div class="staataBox">
            <div class="staataTl">{:lang('团队信息')}</div>
            <div class="staataTableBox">
                <table class="tabletada" border="0" cellspacing="" cellpadding="">
                    <thead>
                        <tr>
                            <th>{:lang('会员')}</th>
                            <th>{:lang('代理等级')}</th>
                            <th>{:lang('直推人数')}</th>
                            <th>{:lang('团队人数')}</th>
                            <th>{:lang('团队累计投资金额')}</th>
                            <th>{:lang('操作')}</th>
                        </tr>
                    </thead>
            <tbody id="content" style="overflow: scroll;">
            </tbody>
                </table>
            </div>
        </div>
    </div>
{include file="public/footer" /}
<script src="/static/home/echarts.min.js" type="text/javascript" charset="utf-8"></script>
<script>
    mui('.mui-scroll-wrapper').scroll({
        deceleration: 0.0005
    });
    $.get("{:url('Team/getTeamInfo')}", function(res){
        console.log(res.user);
        $('#tjr_num').html(res.user.child.child);
        $('#team_num').html(res.user.child.team);
        $('#team_invest_total').html(res.user.invest);
    });
    $(document).ready(function () {
        ajaxGetContent();
    });
    var page = 0,stop = true, user_id = {$user['id']};

    function ajaxGetContent() {
        if (stop == true || page == 0) {
            stop = false;
            if (page == 0) {
                $('#content').html('');
            }

            $.ajax({
                type: "POST",
                url: "{:url('Team/ztIndex')}",//+tab,
                data: {p: page, user_id:user_id},
                success: function (data) {
                    page += 1;
                    $('.loadAdd').hide();
                    // layer.close(getMoreLoad);
                    if ($.trim(data) == '') {
                        stop = false;
                        if (page >= 2) {
                            $('.loadAdd_bottom').show();
                        } else if (page == 1) {
                            $('.loadAdd_nodata').show();
                        }
                    } else {
                        stop = true;
                        let html = '';
                        for(var i=0;i<data.data.length;i++){
                            html += '<tr><td>'+data.data[i]['username']+'</td>';
                            html += '<td>'+data.data[i]['level']+'</td>';
                            html += '<td>'+data.data[i]['child']['child']+'</td>';
                            html += '<td>'+data.data[i]['child']['team']+'</td>';
                            html += '<td>$'+(data.data[i]['invest'] ? data.data[i]['invest'] : 0)+'</td>';
                            html += '<td><div class="click_next_team" data-id="'+data.data[i]['id']+'">';    
                            html += '{:lang('查看下一级')}</div></td></tr>';
                        }
                        $('#content').append(html);
                    }
                }, error: function () {
                    mui.toast('网络失败，请刷新后重试', {duration: 'long', type: 'div'})
                }
            });
        }
    }

    mui('body').on('tap', '.click_next_team', function(){
        user_id = $(this).data('id');
        page = 0;
        ajaxGetContent();
        $('#teamInfo').hide();
        $('#close_btn').show();
    });

    mui('.mui-scroll-wrapper').scroll({
        deceleration: 0.0005
    });

    mui('body').on('tap', '.click_close', function(){
        user_id = {$user['id']};
        page = 0;
        ajaxGetContent();
        $('#teamInfo').show();
        $('#close_btn').hide();
    });
</script>


</body></html>